#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
string s;
int main(void){
    int n;
    scanf("%d",&n);
    cin >> s;
    priority_queue<int,vector<int>,greater<int>> divi;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            divi.push(i);
            divi.push(n/i);
        }
    }
    int pre=0;
    while(divi.size()!=0){
        int d=divi.top();
        divi.pop();
        if(pre==d){
            continue;
        }
        pre=d;
        int i=0;
        int j=d-1;
        while(i<j){
            char t=s[i];
            s[i]=s[j];
            s[j]=t;
            i++;
            j--;
        }
    }
    cout << s << endl;
    return 0;
}
